// 引入公共方法
import './public.js';
import config from './config.js';
const ncp = require('copy-paste')
// 打开应用
const robot = require("robotjs");
// 鼠标移动插件引用
const fs = require('fs');
const ks = require('node-key-sender');
const waitTime = config.waitTime;
// 延时函数
const delayFn = (time) => {
    return new Promise((res, rej) => {
        setTimeout(() => {
            res()
        }, time);
    })
}
// 调用日报文件
const workTxt = (file) => {
    return new Promise((res, rej) => {
        fs.readFile(file, 'utf-8', (a, b) => {
            if (!a) {
                res(b)
            }
            rej()
        });
    })
}
// 复制方法
const copyFn = (workTxtContent) => {
    return new Promise((res, rej) => {
        ncp.copy(workTxtContent, function () {
            res()
        })
    })
}
const mainScript = () => {
    delayFn(waitTime).then(async (res) => {
        // 打开工作台
        robot.moveMouse(530, 570);
        robot.setMouseDelay(500)
        robot.mouseClick();
        // 打开日报
        robot.moveMouse(1130, 610);
        robot.setMouseDelay(500)
        robot.mouseClick();
        // 打开技术汇报
        robot.moveMouse(1180, 610);
        robot.setMouseDelay(500)
        robot.mouseClick();
        // 点击一下进行输入
        // await delayFn(500);
        robot.setMouseDelay(500);
        robot.mouseClick();
        await delayFn(1000);
        robot.moveMouse(1180, 560);
        robot.setMouseDelay(1500);
        robot.mouseClick();
        await ks.sendCombination(['control', 'ctrl', 'a']);
        robot.keyTap('backspace');
        const workTxtContent = await workTxt('./work.md');
        await copyFn(workTxtContent);
        ks.sendCombination(['control', 'ctrl', 'v']);
        robot.moveMouse(1160, 340);
        robot.mouseClick();
        robot.moveMouse(1160, 790);
        // 正式模式
        if (config.mode === 'p') {
            robot.mouseClick();
        }
    });

}
mainScript()
